import 'package:flutter/material.dart';
import 'package:flutter_study/widget/MyString.dart';

///路由 2 desc：和是一个demo很相似，简单改造代码演示
///then
class RouteDemo2 extends StatelessWidget {
  final String title;

  const RouteDemo2({Key? key, required this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          title,
          style: TextStyle(color: Colors.white, fontSize: 20),
        ),
        centerTitle: true,
        elevation: 10.0,
      ),
      body: RouteWidgetX(),
    );
  }
}

class RouteWidgetX extends StatelessWidget {
  const RouteWidgetX({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Center(
        child: RaisedButton(
          onPressed: () {
            Navigator.pushNamed(context, "menu2",
                    arguments: {"key_a": "value_a", "key_b": "value_b"})
                .then((value) => {print("返回值： $value")});
          },
          child: Text(
            "登录",
            style: TextStyle(color: Colors.blue, fontSize: 20),
          ),
        ),
      ),
    );
  }
}

///MenuPage
class MenuPage2 extends StatelessWidget {
  final String title;

  const MenuPage2({Key? key, required this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    //
    dynamic arguments = ModalRoute.of(context)!.settings.arguments;

    //获取arguments的name作为界面标题

    return Scaffold(
      appBar: AppBar(
        title: Text(
          "$title  arguments:$arguments",
          style: TextStyle(color: Colors.white, fontSize: 20),
        ),
        centerTitle: true,
        elevation: 10.0,
      ),
      body: MenuPageWidgetX(),
    );
  }
}

class MenuPageWidgetX extends StatelessWidget {
  const MenuPageWidgetX({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Center(
        child: RaisedButton(
          onPressed: () {
            //返回
            Navigator.of(context).pop({
              "返回值": {
                "key_1": "value1",
                "key_2": 222,
              }
            });
          },
          child: Text(
            "返回",
            style: TextStyle(color: Colors.blue, fontSize: 20),
          ),
        ),
      ),
    );
  }
}
